import { defineStore } from "pinia";
import userStore from "./user";

const useCounterStore = defineStore('countInfo',{
    state: () => {
        return {
            salary: 20,
            count: 66,
            list: [],
        }
    },
    getters: {
        showMessage() {
            const user = userStore();
            return `${user.nickName} -count`
        }
    },
    actions:{
        increment(state) {
            // 注意：state的结果是undefined 所以actions只能通过this访问store。getter的话state和this都能访问。
            console.log('counter-actions-state', state);
            this.count++;
        },
        incrementNum(num) {
            this.count += num;
        },
        async axiosData() {
            // const res = await fetch("http://-----------------")
            // if(code ==200){
                //收到数据保存到store
                // this.list = res.data.list
                // return "ok"
            // }
            // const counterStore = useCounter()counterStore.axiosData().then(res =>{console.log("成功",res);
        }
    }
});

export default useCounterStore
